#ifndef GAME_H
#define GAME_H

#include <cstdint>
#include "common.h"


// 游戏主类
class Game {
public:
    Game();
    ~Game();
    
    // 游戏流程控制
    void initialize();
    void quickStart();
    void run();
    void gameOver();
    
    // 游戏操作
    void processInput();
    void update();
    void renderRefresh();
    
    // 状态查询
    bool isRunning() const { return status == GameStatus::Running; }
    bool isOver() const { return status == GameStatus::GameOver; }
    int getScore() const { return score; }
    double getFrameDelay() const { return InitialInterval * 200.0 / speed / speedMultiplier; }

    void changeDirection(Direction newDirection);
    void toggleMode();
    void togglePause();
    
private:
    // 游戏状态
    GameStatus status;
    GameMode mode;
    Direction currentDirection;
    SnakeNode* head;
    SnakeNode* tail;
    Food food;
    int score;
    int speed;
    int speedMultiplier;
    bool wallPassing;
    
    // 内部方法
    void setupMap();
    void createSnake();
    void spawnFood();
    bool checkCollision() const;
    void moveSnake();
    void cleanupSnake();
    void renderInit();
    void renderSnake(bool deleteTail);

    int getInput();
    
    // 辅助方法
    bool isPositionOccupied(int x, int y) const;

};

#endif // GAME_H